export function isLogin() {
  // 判断token是否存在localStorage或session.Storage
  if (localStorage.getItem('token') || sessionStorage.getItem('token')) {
    return true
  } else {
    return false
  }
}

import router from '@/router/index.js';
import { checkUserPermission } from '@/api/index.js'
import { showConfirmDialog } from 'vant';
import { getUserId } from './getUserId';
export async function checkPermission() {
  const userId = getUserId()
  const res = await checkUserPermission(userId)
  if (!res.permission) {
    showConfirmDialog({
      message:
        `${res.message}`,
    })
      .then(() => {
        router.push('/login')
      })
      .catch(() => {
        router.push('home')
      });
    return false
  }
  return true
}

export async function checkUser(role) {
  const userId = getUserId()
  const res = await checkUserPermission(userId)
  if (role === 'admin') {
    return res.permission && userId === 9
  } else {
    return res.permission
  }
}
